$('#logout').on('click', function() {
  var isConfirm = confirm('您真的要退出吗?')
  if (isConfirm) {
    // alert('用户点击了确认按钮')
    $.ajax({
      type: 'post',
      url: '/logout',
      success: function() {
        location.href = 'login.html'
      },
      error: function() {
        alert('退出失败')
      }
    })
  }
})

// opts: fileId, hiddenId, previewId
function upload(opts) {
  $('#' + opts.fileId).on('change', function() {
    var file = this.files[0]
    var formData = new FormData()
    formData.append('img', file)
    $.ajax({
      type: 'post',
      url: '/upload',
      data: formData,
      processData: false,
      contentType: false,
      success: function(res) {
        console.log(res, 'res')
        $('#' + opts.hiddenId).val(res[0].img)
        if (opts.previewId) {
          $('#' + opts.previewId).attr('src', res[0].img)
        }
      }
    })
  })
}
